home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / scripts / elements / hints.cnh < prev    next >
Encoding:
Text File  |  2002-05-10  |  4.2 KB  |  205 lines

  1. // messages to be used by components
  2. message ShowHint(szx _szText);
  3. message MoveHint(i32x _posX, i32x _posY);
  4. message HideHint();
  5.  
  6. // messages to be used by manager
  7. //message ResetHint();
  8. //message HintReset();
  9. message HintSet(szx _szText);
  10. message HintReset();
  11.  
  12. func void Hint_OnLoop(f32x _fDelta);
  13. func void Hint_Reset();
  14. func void Hint_Set(szx _szText);
  15.  
  16. //
  17. //
  18. //
  19. class Gui_dtHint
  20. {
  21.     var Gui_Component gcBorder;
  22.     var Gui_Component gcBack;
  23.     var Gui_Component gcText;
  24.     var i32x iWidth, iHeight;
  25.     var f32x fTimer;
  26.     var boolx bRunning;
  27.     var szx szText;
  28. };
  29.  
  30. class Gui_dtHintTimer
  31. {
  32. };
  33.  
  34. //
  35. //
  36. //
  37. interface Gui_iHint
  38. {
  39.     Hint_Set        HintSet;
  40.     Hint_Reset        HintReset;
  41. }
  42.  
  43.  
  44. //
  45. //
  46. //
  47. interface Gui_iHintTimer
  48. {
  49.     Hint_OnLoop        Loop;
  50. }
  51.  
  52.  
  53. //
  54. //
  55. //
  56. interface Gui_iHintCaption
  57. {
  58. }
  59.  
  60.  
  61. //
  62. //
  63. //
  64. func Gui_Component NewHint()
  65. {
  66.     var Gui_Component pComposite, pText, pBack, pBorder;
  67.     var Menu_Sprite sprite;
  68.  
  69.     pComposite = NewObject(Gui_iHint);
  70.     var Gui_dtHint pdtHint;
  71.     pdtHint = new Gui_dtHint;
  72.     SetData(pComposite, pdtHint);
  73.  
  74.     // border
  75.     pBorder = NewBitmap(smWhite, 0);
  76.     SetShadingMode(GetSprite(pBorder), DLC_GouraudMode_ModulateDiffuse, DLC_GouraudMode_ModulateDiffuse);
  77.     SetBlendingMode(GetSprite(pBorder), DLC_Blend_AlphaBlend);
  78.     SetAlign(pBorder, e_GUI_HAlign_Zoom, e_GUI_VAlign_Zoom);
  79.     SetColor(pBorder, cHintTextColor);
  80.     MountComponent(pComposite, pBorder);
  81.     pdtHint.gcBorder = pBorder;
  82.  
  83.     // back
  84.     pBack = NewBitmap(smWhite, 0);
  85.     SetShadingMode(GetSprite(pBack), DLC_GouraudMode_ModulateDiffuse, DLC_GouraudMode_ModulateDiffuse);
  86.     SetBlendingMode(GetSprite(pBack), DLC_Blend_AlphaBlend);
  87.     SetAlign(pBack, e_GUI_HAlign_Zoom, e_GUI_VAlign_Zoom);
  88.     SetColor(pBack, cHintBackColor);
  89.     MountComponent(pComposite, pBack);
  90.     pdtHint.gcBack = pBack;
  91.  
  92.     // text
  93.     pText = NewContainer(Gui_iHintCaption);
  94.     sprite = NewSprite2D(pHintFont);
  95.     SetShadingMode(sprite,DLC_GouraudMode_ModulateDiffuse,DLC_GouraudMode_Decal);
  96.     // Attach the sprite to this container
  97.     AttachSprite(pText, sprite);
  98.     SetAlign(pText, e_GUI_HAlign_Center, e_GUI_VAlign_Center);
  99.     MountComponent(pComposite, pText);
  100.     SetColor(pText, cHintTextColor);
  101.     pdtHint.gcText = pText;
  102.  
  103.     pdtHint.gcBorder<<Hide();
  104.     pdtHint.gcBack<<Hide();
  105.     pdtHint.gcText<<Hide();
  106.     pComposite<<Disable();
  107.  
  108.     return pComposite;
  109. }
  110.  
  111.  
  112. //
  113. //
  114. //
  115. func void Hint_OnLoop(f32x _fDelta)
  116. {
  117.     var Gui_Component pthis, pcomponent; 
  118.     pthis = GetThis();
  119.     var Gui_dtHint pdtData;
  120.     pdtData = GetPrimaryData(pthis);
  121.     
  122.     // increase timer
  123.     pdtData.fTimer = pdtData.fTimer + _fDelta;
  124.  
  125.     if ((pdtData.fTimer > fHintDelay) && (pdtData.bRunning))
  126.     {
  127.         RemoveInterface(pthis);
  128.  
  129.         var i32x i, iNumComponents;
  130.         iNumComponents = GetComponentNumber(pthis);
  131.         i = 0;
  132.         while (i<iNumComponents)
  133.         {
  134.             pcomponent = GetComponent(pthis, i);
  135.             if (pcomponent)
  136.             {
  137.                 pcomponent<<Show();
  138.             }
  139.             i = i + 1;
  140.         }
  141.     }
  142.  
  143.     if (!pdtData.bRunning)
  144.     {
  145.         RemoveInterface(pthis);
  146.     }
  147. }
  148.  
  149.  
  150. func void Hint_Set(szx _szText)
  151. {
  152.     var Gui_Component pthis, pcomponent; 
  153.     var Menu_Sprite sprite;
  154.     pthis = GetThis();
  155.     var Gui_dtHint pdtHint;
  156.     pdtHint = GetPrimaryData(pthis);
  157.  
  158.     if (!pdtHint.bRunning)
  159.     {
  160.         pdtHint.bRunning = true;
  161.         pdtHint.fTimer = 0.0;
  162.         
  163.         pdtHint.szText = _szText;
  164.  
  165.         sprite = GetSprite(pdtHint.gcText);
  166.         pdtHint.iWidth = PrecalcTextWidth(sprite, pdtHint.szText) + 10;
  167.         pdtHint.iHeight = PrecalcTextHeight(sprite, pdtHint.szText);
  168.         SetText(sprite, pdtHint.szText);
  169.  
  170.         StretchTo(pdtHint.gcBorder, pdtHint.iWidth + 2, pdtHint.iHeight + 2);
  171.  
  172.         StretchTo(pdtHint.gcText, pdtHint.iWidth, pdtHint.iHeight);
  173.         MoveTo(pdtHint.gcText, 1, 1);
  174.  
  175.         StretchTo(pdtHint.gcBack, pdtHint.iWidth, pdtHint.iHeight);
  176.         MoveTo(pdtHint.gcBack, 1, 1);
  177.         
  178.         StretchTo(pthis, pdtHint.iWidth, pdtHint.iHeight);
  179.     }
  180. }
  181.  
  182.  
  183.  
  184. func void Hint_Reset()
  185. {
  186.     var Gui_Component pthis, pcomponent; 
  187.     pthis = GetThis();
  188.     var Gui_dtHint pdtHint;
  189.     pdtHint = GetPrimaryData(pthis);
  190.  
  191.     pdtHint.fTimer = 0.0;
  192.     pdtHint.bRunning = false;
  193.     var i32x i, iNumComponents;
  194.     iNumComponents = GetComponentNumber(pthis);
  195.     i = 0;
  196.     while (i<iNumComponents)
  197.     {
  198.         pcomponent = GetComponent(pthis, i);
  199.         if (pcomponent)
  200.         {
  201.             pcomponent<<Hide();
  202.         }
  203.         i = i + 1;
  204.     }
  205. }